package com.gz.springboot.config;

import com.gz.springboot.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig /*implements WebMvcConfigurer*/ {

    //方法一
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                //注意拦截器是/**,过滤器是/*
                registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").
                        excludePathPatterns("/","/login","/images/**",
                                "/upload.html","/upload");
            }
        };
    }

    //方法二
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //"/**" 拦截所有的请求
//        //excludePathPatterns 排除特定页面
//        registry.addInterceptor(new LoginInterceptor()).
//                addPathPatterns("/**").excludePathPatterns("/","/login","/images/**");
//    }
}
